package applet;

import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JSpinner;

public class MessageDialog extends JDialog implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static final int BUTTON_WIDTH = 100;
	
	private CustomJButton okButton;
	
	public MessageDialog(Window parent, String message) {
		super(parent, Dialog.ModalityType.APPLICATION_MODAL);
		
		setSize(300, 150);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setLayout(new BorderLayout());

		Box vBox = Box.createVerticalBox();
		
		vBox.add(Box.createVerticalStrut(10));
		Box messageBox = Box.createHorizontalBox();
		messageBox.add(Box.createHorizontalStrut(10));
		messageBox.add(new CustomJLabel(message));
		messageBox.add(Box.createHorizontalStrut(10));
		vBox.add(messageBox);
		vBox.add(Box.createVerticalStrut(10));
		Box buttonBox = Box.createHorizontalBox();
		buttonBox.add(Box.createHorizontalGlue());
		okButton = new CustomJButton("Ok");
		buttonBox.add(okButton);
		buttonBox.add(Box.createHorizontalGlue());
		vBox.add(buttonBox);
		vBox.add(Box.createVerticalStrut(10));
		okButton.addActionListener(this);
		
		add(vBox, BorderLayout.CENTER);
		pack();
		setBounds(parent.getBounds().x+(parent.getBounds().width-getWidth())/2, parent.getBounds().y+(parent.getBounds().height-getHeight())/2, getWidth(), getHeight());
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource() == okButton) {
			this.setVisible(false);
			this.dispose();
		}
	}
	

	private class CustomJLabel extends JLabel {
		public CustomJLabel(String label) {
			super(label);
			setFont(DisplayApplet.customFont);
		}
		@Override
		public Dimension getPreferredSize() {
			int width = super.getPreferredSize().width;
			return new Dimension(width, DisplayApplet.ITEM_BUTTON_HEIGHT);
		}
		@Override
		public Dimension getMinimumSize() {
			int width = super.getMinimumSize().width;
			return new Dimension(width, DisplayApplet.ITEM_BUTTON_HEIGHT);
		}
		@Override
		public Dimension getMaximumSize() {
			int width = super.getMaximumSize().width;
			return new Dimension(width, DisplayApplet.ITEM_BUTTON_HEIGHT);
		}
	}

	private class CustomJButton extends JButton {
		public CustomJButton(String s) {
			super(s);
			setFont(DisplayApplet.customFont);
		}
		@Override
		public Dimension getPreferredSize() {
			//int width = super.getPreferredSize().width;
			return new Dimension(BUTTON_WIDTH, DisplayApplet.ITEM_BUTTON_HEIGHT);
		}
		@Override
		public Dimension getMinimumSize() {
			//int width = super.getMinimumSize().width;
			return new Dimension(BUTTON_WIDTH, DisplayApplet.ITEM_BUTTON_HEIGHT);
		}
		@Override
		public Dimension getMaximumSize() {
			//int width = super.getMaximumSize().width;
			return new Dimension(BUTTON_WIDTH, DisplayApplet.ITEM_BUTTON_HEIGHT);
		}
	}

}
